<?php

// +----------------------------------------------------------------------
// | H1CMS © OpenSource CMS
// +----------------------------------------------------------------------
// | Copyright (c) 2014-2016 http://www.h1cms.com All rights reserved.
// | Copyright (c) 2014-2016 嘉兴领格信息技术有限公司，并保留所有权利。
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Allen <allen@lg4.cn>
// +----------------------------------------------------------------------

namespace Lg\Http;

use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
use Symfony\Component\HttpFoundation\JsonResponse;

/**
 * Description of Response
 *
 * @author getssl
 */
class Response extends SymfonyResponse {

    public static function make($content = '', $status = 200, $headers = array()) {
        return new Response($content, $status, $headers);
    }
    
    /**
     * 
     * @param type $data
     * @param type $status
     * @param type $headers
     * @return \Symfony\Component\HttpFoundation\JsonResponse
     */
    public static function json($data = [], $status = 200, $headers = array()) {
        return JsonResponse::create($data, $status, $headers);
    }

    public function header($key, $values, $replace = true) {
        $this->headers->set($key, $values, $replace);
        return $this;
    }

    public function withHeaders(array $headers) {
        foreach ($headers as $key => $value) {
            $this->headers->set($key, $value);
        }
        return $this;
    }

    public function cookie($cookie) {
        return call_user_func_array([$this, 'withCookie'], func_get_args());
    }

    public function withCookie($cookie) {
        if (is_string($cookie) && function_exists('cookie')) {
            $cookie = call_user_func_array('cookie', func_get_args());
        }
        $this->headers->setCookie($cookie);
        return $this;
    }

    public function content() {
        return $this->getContent();
    }

    public function status() {
        return $this->getStatusCode();
    }

}
